//
//  SAOperatingProfitCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/7/26.
//

#import "SAOperatingProfitCell.h"
#import "SAMemberHistoryModel.h"

@interface SAOperatingProfitCell ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *orderNoLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *profitLab;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation SAOperatingProfitCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAMemberHistoryModel *)model {
    _model = model;
    if (model.memberName.length == 0) {
        self.titleLab.text = @"散客";
    }else {
        self.titleLab.text = model.memberName;
    }
    self.orderNoLab.text = model.salesOrderNo;
    self.priceLab.text = [NSString stringWithFormat:@"￥%0.2lf",[model.actualPrice doubleValue]/100.f];
    self.profitLab.text = [NSString stringWithFormat:@"数量%@,毛利￥%0.2lf",model.totalCount,[model.profit doubleValue]/100.f];
    
    SAUserInfo *userInfo = [SAValueManger shareInStance].userInfo;
    if (userInfo.userType != 1) {
        self.profitLab.text = [NSString stringWithFormat:@"数量%@,毛利￥******",model.totalCount];
    }
}

-(void)initUI {
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.orderNoLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.profitLab];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.imageV];
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(30, 11, 100, 20)];
        _titleLab.textColor = kBlackColor;
        _titleLab.font = kFont(15);
        _titleLab.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLab;
}

-(UILabel *)orderNoLab {
    if (!_orderNoLab) {
        _orderNoLab = [[UILabel alloc] initWithFrame:SARectMake(30, 41, 100, 20)];
        _orderNoLab.textColor = kLightgGrayColor;
        _orderNoLab.font = kFont(15);
        _orderNoLab.textAlignment = NSTextAlignmentLeft;
    }
    return _orderNoLab;
}

-(UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(240), kScaleNum(11), kScaleNum(205), kScaleNum(20))];
        _priceLab.textColor = kBlackColor;
        _priceLab.font = kFont(15);
        _priceLab.textAlignment = NSTextAlignmentRight;
        _priceLab.adjustsFontSizeToFitWidth = YES;
        _priceLab.minimumScaleFactor = 0.8;
    }
    return _priceLab;
}

-(UILabel *)profitLab {
    if (!_profitLab) {
        _profitLab = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(240), kScaleNum(41), kScaleNum(205), kScaleNum(20))];
        _profitLab.textColor = kLightgGrayColor;
        _profitLab.font = kFont(15);
        _profitLab.textAlignment = NSTextAlignmentRight;
        _profitLab.adjustsFontSizeToFitWidth = YES;
        _profitLab.minimumScaleFactor = 0.8;
    }
    return _profitLab;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(0), kScreenWidth, kScaleNum(1))];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(30), kScaleNum(25), kScaleNum(20), kScaleNum(20))];
        _imageV.image = [UIImage imageNamed:@"gray_BigRightArrow"];
    }
    return _imageV;
}

@end
